#ifndef MYTCP_H
#define MYTCP_H

#include "Task.h"

#include <QMutex>
#include <QObject>
#include <QTcpSocket>
#include <QTextCodec>
#include <QThread>
#include <QTimer>

class MyTcp : public QObject
{
    Q_OBJECT
public:
    explicit MyTcp(QObject *parent = nullptr);
    ~MyTcp();
    QTcpSocket* getMyTcpSocket();
    static quint16 CRC16_chart(uchar *puchMsg, unsigned short usDataLen);
     Task *getTask();
     QString &getIp();
     int &getPort();
private:
    QString ip="192.168.1.166";
    int port=8059;
    QTcpSocket *myTcpSock=nullptr;
    QThread *myThread=nullptr;
    QMutex *tcpLock=nullptr;
    int receiveWaitM=10;
    QTimer *receiveTimer=nullptr;//回复定时器
    Task task;
    QTextCodec *codec=QTextCodec::codecForName("GBK");
signals:
    void disconnected_signal();
public slots:
    void init();
    void connectServer();
    void write(QString str,bool istimer);
    void handleReadyRead();
    void receiveTimeout();
    void sendServerData_slot(QString str,bool isTimer);

};

#endif // MYTCP_H
